package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryBrandService;
import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: CategoryBrandController
 * Package: com.atguigu.spzx.manager.controller
 * Description:
 *
 * @Author 刘强
 * @Create 2024/7/5 16:48
 * @Version 1.0
 */
@RestController
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {
    @Resource
    private CategoryBrandService categoryBrandService;

    /**
     * 根据分类id查询品牌
     * @param id
     * @return
     */
    @GetMapping("findBrandByCategoryId/{id}")
    public Result findBrandByCategoryId(@PathVariable Long id){
        List<Brand> brandByCategoryId = categoryBrandService.findBrandByCategoryId(id);
        return Result.build(brandByCategoryId,ResultCodeEnum.SUCCESS);
    }

    @DeleteMapping("deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        categoryBrandService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据id修改
     * @param categoryBrand
     * @return
     */
    @PutMapping("updateById")
    public Result updateById(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.updateById(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 新增分类菜单
     * @return
     */
    @PostMapping("save")
    public Result save(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.save(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     *  分页带条件查询分类品牌
     * @param categoryBrandDto
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("{pageNum}/{pageSize}")
    public Result findByPage(CategoryBrandDto categoryBrandDto,
                             @PathVariable Long pageNum,
                             @PathVariable Long pageSize){
        PageInfo<CategoryBrand> page = categoryBrandService.findByPage(categoryBrandDto,pageNum,pageSize);
        return Result.build(page, ResultCodeEnum.SUCCESS);
    }
}
